home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 2010 April
/
PCWorld0410.iso
/
pluginy Firefox
/
55375
/
55375.xpi
/
chrome
/
chromeFiles
/
content
/
btServiceUtilities.js
< prev
next >
Wrap
Text File
|
2009-11-15
|
12KB
|
342 lines
function finalUIStartup(brandObject) {
this.installXPIs(brandObject);
}
function profileAfterChange(brandObject) {
/* If we are switching to big boom, set the theme to classic */
try {
if (gPrefBranch.getBoolPref("extensions.brandthunder.bigBoom") == true) {
gPrefBranch.setCharPref("general.skins.selectedSkin", "classic/1.0");
}
} catch (ex) {}
}
function profileBeforeChange(brandObject) {
var skinSwitchPending = gPrefBranch.getBoolPref("extensions.dss.switchPending");
if (skinSwitchPending) {
gPrefBranch.setBoolPref("extensions.brandthunder.bigBoom", false);
}
try {
gPrefBranch.clearUserPref("general.useragent.extra.brandthunder");
} catch (ex) {}
try {
/* Don't clear the keywordURL pref if we weren't the ones who set it */
var keywordURL = gPrefBranch.getCharPref("keyword.URL");
if (keywordURL.match("chrff-brandt_off")) {
gPrefBranch.clearUserPref("keyword.URL");
}
} catch (ex) {}
}
function firstRun (brandObject) {
function getVersionFromExtension(extfile) {
var zipReader = Cc["@mozilla.org/libjar/zip-reader;1"]
.createInstance(Ci.nsIZipReader);
try {
zipReader.init(extfile);
zipReader.open();
} catch(ex) {
zipReader.open(extfile);
}
var tempfile = Cc["@mozilla.org/file/directory_service;1"]
.getService(Ci.nsIProperties)
.get("TmpD", Ci.nsIFile);
tempfile.append("install.rdf");
tempfile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0600);
zipReader.extract("install.rdf", tempfile);
zipReader.close();
var ioServ = Cc["@mozilla.org/network/io-service;1"]
.getService(Ci.nsIIOService);
var fph = ioServ.getProtocolHandler("file")
.QueryInterface(Ci.nsIFileProtocolHandler);
var fileURL = fph.getURLSpecFromFile(tempfile);
var RDF = Cc["@mozilla.org/rdf/rdf-service;1"]
.getService(Ci.nsIRDFService);
var InstallManifestRoot = RDF.GetResource("urn:mozilla:install-manifest");
var ds = RDF.GetDataSourceBlocking(fileURL);
var target = ds.GetTarget(InstallManifestRoot,
RDF.GetResource("http://www.mozilla.org/2004/em-rdf#version"), true);
return target.QueryInterface(Ci.nsIRDFLiteral).Value;
}
function extensionEnabled(extensionID) {
var rdfs = Cc["@mozilla.org/rdf/rdf-service;1"]
.getService(Ci.nsIRDFService);
var extensionDS= Cc["@mozilla.org/extensions/manager;1"]
.getService(Ci.nsIExtensionManager).datasource;
var extension = rdfs.GetResource("urn:mozilla:item:" + extensionID);
var arc = rdfs.GetResource("http://www.mozilla.org/2004/em-rdf#userDisabled");
var userDisabled = extensionDS.GetTarget(extension, arc, true);
if (userDisabled) {
userDisabled = userDisabled.QueryInterface(Ci.nsIRDFLiteral).Value;
return (userDisabled == false);
}
return true;
}
function extensionGetHomePage(extensionID) {
var rdfs = Cc["@mozilla.org/rdf/rdf-service;1"]
.getService(Ci.nsIRDFService);
var extensionDS= Cc["@mozilla.org/extensions/manager;1"]
.getService(Ci.nsIExtensionManager).datasource;
var extension = rdfs.GetResource("urn:mozilla:item:" + extensionID);
var arc = rdfs.GetResource("http://www.mozilla.org/2004/em-rdf#homepageURL");
var homePage = extensionDS.GetTarget(extension, arc, true);
if (homePage) {
homePage = homePage.QueryInterface(Ci.nsIRDFLiteral).Value;
return homePage;
}
return "";
}
var firstrun = true;
var btClientPrefBranch = Cc["@mozilla.org/preferences-service;1"]
.getService(Ci.nsIPrefService)
.getBranch("extensions.brandthunder." + brandObject.clientCode + ".");
var btPrefBranch = Cc["@mozilla.org/preferences-service;1"]
.getService(Ci.nsIPrefService)
.getBranch("extensions.brandthunder.");
var em = Cc["@mozilla.org/extensions/manager;1"]
.getService(Ci.nsIExtensionManager);
var newVersion = em.getItemForID(brandObject.extensionID).version;
var installedVersion;
try {
installedVersion = btClientPrefBranch.getCharPref("installedVersion");
} catch (ex) {
installedVersion = "0";
}
btClientPrefBranch.setCharPref("installedVersion", newVersion);
try{
firstrun = btClientPrefBranch.getBoolPref("firstrun");
if (firstrun == false) {
/* Ignore firstrun pref if we aren't a Boom */
try {
btPrefBranch.getCharPref("currentBoom");
var versionChecker = Cc["@mozilla.org/xpcom/version-comparator;1"]
.getService(Ci.nsIVersionComparator);
/* if new version > curversion */
if (versionChecker.compare(newVersion, installedVersion) > 0) {
btClientPrefBranch.setBoolPref("upgrade", true);
/* Handle surf canyon upgrade */
try {
var partner_code = gPrefBranch.getCharPref("surfcanyon.partner_code");
if (partner_code == "BT") {
var sub_partner_code = gPrefBranch.getCharPref("surfcanyon.sub_partner_code");
if (sub_partner_code == brandObject.shortName) {
gPrefBranch.setBoolPref("surfcanyon.added_to_searchbar", true);
}
}
} catch (ex) {}
/* If the user hasn't explicitly set it to false, set it to true */
/* This is to handle the upgrade case */
if (!btPrefBranch.prefHasUserValue("tabSearch")) {
btPrefBranch.setBoolPref("tabSearch", true);
}
if (!btPrefBranch.prefHasUserValue("keywordSearch")) {
btPrefBranch.setBoolPref("keywordSearch", true);
}
}
return;
} catch (ex) {
/* If currentBoom wasn't set, this is a first run from a toolbar, not a boom */
/* Set the pref so we go through this code, but not the front end first run */
btClientPrefBranch.setBoolPref("firstrun", false);
/* If we are moving from toolbar to boom, always an upgrade */
btClientPrefBranch.setBoolPref("upgrade", true);
}
}
} catch(e) {
//nothing
}
/* Default to false - we'll set them to true on either optin */
/* or first run */
if (!btPrefBranch.prefHasUserValue("tabSearch")) {
btPrefBranch.setBoolPref("tabSearch", false);
}
if (!btPrefBranch.prefHasUserValue("keywordSearch")) {
btPrefBranch.setBoolPref("keywordSearch", false);
}
/* Surf Canyon pref setting code */
try {
var partner_code = gPrefBranch.getCharPref("surfcanyon.partner_code");
if (partner_code == "BT") {
var sub_partner_code = gPrefBranch.getCharPref("surfcanyon.sub_partner_code");
if (sub_partner_code == brandObject.shortName) {
gPrefBranch.setBoolPref("surfcanyon.added_to_searchbar", true);
}
}
} catch (ex) {}
/* For first run, set the theme to classic,
set the currentBoom, and set big boom */
gPrefBranch.setCharPref("general.skins.selectedSkin", "classic/1.0");
var initialBoom;
var cookieManager = Components.classes["@mozilla.org/cookiemanager;1"]
.getService(Components.interfaces.nsICookieManager);
var e = cookieManager.enumerator;
while (e.hasMoreElements()) {
var cookie = e.getNext();
if (cookie && cookie instanceof Components.interfaces.nsICookie) {
if (cookie.name == brandObject.shortName) {
if (brandObject.booms[cookie.value]) {
initialBoom = cookie.value;
cookieManager.remove(cookie.domain, cookie.name, cookie.path, false);
break;
}
}
}
}
if (!initialBoom) {
for (let i in brandObject.booms) {
initialBoom = i;
break;
}
}
btPrefBranch.setCharPref("currentBoom", initialBoom);
btPrefBranch.setBoolPref("bigBoom", true);
var em = Cc["@mozilla.org/extensions/manager;1"]
.getService(Ci.nsIExtensionManager);
/* Before we do anything, uninstall old CCK */
/* Set a pref which indicates we are upgrading from an old version */
if (brandObject.cckID) {
if (em.getInstallLocation(brandObject.cckID)) {
em.uninstallItem(brandObject.cckID);
}
}
/* If we have a themeID, uninstall the old theme */
if (brandObject.themeID) {
if (em.getInstallLocation(brandObject.themeID)) {
em.uninstallItem(brandObject.themeID);
}
}
/* Disable any other brand thunder extensions by enumerating through */
/* all extensions and looking for http://brandthunder.com */
/* ugly I know */
var items = em.getItemList(Ci.nsIUpdateItem.TYPE_EXTENSION, {});
for (var i = 0; i < items.length; i++) {
if (items[i].id != brandObject.extensionID) {
if (extensionEnabled(items[i].id)) {
if (extensionGetHomePage(items[i].id).match("brandthunder.com") &&
(!extensionGetHomePage(items[i].id).match("boom"))) {
em.disableItem(items[i].id);
}
}
}
}
}
function installXPIs(brandObject) {
var btClientPrefBranch = Cc["@mozilla.org/preferences-service;1"]
.getService(Ci.nsIPrefService)
.getBranch("extensions.brandthunder." + brandObject.clientCode + ".");
/* Don't install any XPIs on an upgrade */
/* We'll set a pref and install them if there is opt in */
var upgrade = false;
try {
upgrade = btClientPrefBranch.getBoolPref("upgrade");
if (upgrade) {
return;
}
} catch (ex) {}
var items_installed = false;
var em = Cc["@mozilla.org/extensions/manager;1"]
.getService(Ci.nsIExtensionManager);
try {
var extdir = em.getInstallLocation(brandObject.extensionID)
.getItemLocation(brandObject.extensionID);
} catch (ex) {
return;
}
var e = extdir.directoryEntries;
while (e.hasMoreElements()) {
var f = e.getNext().QueryInterface(Components.interfaces.nsIFile);
var splitpath = f.path.split(".");
/* Only load XPI files */
if (splitpath[splitpath.length-1] == "xpi") {
var zipReader = Cc["@mozilla.org/libjar/zip-reader;1"]
.createInstance(Ci.nsIZipReader);
try {
zipReader.init(f);
zipReader.open();
} catch(ex) {
zipReader.open(f);
}
var tempfile = Cc["@mozilla.org/file/directory_service;1"]
.getService(Ci.nsIProperties)
.get("TmpD", Ci.nsIFile);
tempfile.append("install.rdf");
tempfile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0600);
zipReader.extract("install.rdf", tempfile);
zipReader.close();
var ioServ = Cc["@mozilla.org/network/io-service;1"]
.getService(Ci.nsIIOService);
var fph = ioServ.getProtocolHandler("file")
.QueryInterface(Ci.nsIFileProtocolHandler);
var fileURL = fph.getURLSpecFromFile(tempfile);
var RDF = Cc["@mozilla.org/rdf/rdf-service;1"]
.getService(Ci.nsIRDFService);
var InstallManifestRoot = RDF.GetResource("urn:mozilla:install-manifest");
var ds = RDF.GetDataSourceBlocking(fileURL);
var target = ds.GetTarget(InstallManifestRoot,
RDF.GetResource("http://www.mozilla.org/2004/em-rdf#version"), true);
var newVersion = target.QueryInterface(Ci.nsIRDFLiteral).Value;
var target = ds.GetTarget(InstallManifestRoot,
RDF.GetResource("http://www.mozilla.org/2004/em-rdf#id"), true);
var id = target.QueryInterface(Ci.nsIRDFLiteral).Value;
/* check to see if ID is already installed */
var item = em.getItemForID(id);
if (item) {
var curVersion = item.version;
var versionChecker = Cc["@mozilla.org/xpcom/version-comparator;1"]
.getService(Ci.nsIVersionComparator);
/* if new version > curversion */
if (versionChecker.compare(newVersion, curVersion) > 0) {
em.installItemFromFile(f, "app-profile");
items_installed = true;
}
} else {
em.installItemFromFile(f, "app-profile");
items_installed = true;
}
try {
f.remove(true);
} catch (ex) {
/* Ignore error - it's already gone */
/* This happens on FF2 in some cases for some reason */
}
}
}
if (items_installed) {
var nsIAppStartup = Components.classes["@mozilla.org/toolkit/app-startup;1"]
.getService(Components.interfaces.nsIAppStartup);
nsIAppStartup.quit(nsIAppStartup.eRestart | nsIAppStartup.eAttemptQuit);
}
}